package sun.springboot.mqtt_integration.core.messageHandle;

import org.springframework.messaging.Message;

/**
 * 主题筛选、消息处理 事例
 */
public abstract class AbsTopicScreenDetails {


    /**
     * 常量
     */
    public final static String receive = "receive";
    public final static String will = "will";
    public final static String charge = "charge";
    //消息对象
    public Message message;

    public AbsTopicScreenDetails setMessage(Message message) {
        this.message = message;
        return this;
    }

    /**
     * 接收
     */
    public abstract void receive();

    /**
     * 遗嘱
     */
    public abstract void will();

    /**
     * 充电
     */
    public abstract void charge();


    public void screenTopic() {
        //接收
        if (receive.equals(this.topic())) this.receive();
        //遗嘱
        if (will.equals(this.topic())) this.will();
        //充电
        if (charge.equals(this.topic())) this.charge();

    }

    /*默认去标签为mqtt_receivedTopic的值--对应上传主题*/
    private String topic() {
        return this.message.getHeaders().get("mqtt_receivedTopic").toString();
    }

}
